#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
#define endl '\n'
const int maxn = 100 + 50;
const int INF = 1e9;
int n, m, from, to;
int dis[maxn][maxn], dp[maxn];
int book[maxn];


int bfs(int from, int to) {
    dp[from] = 0;
    queue<int> Q;
    Q.push(from);
    book[from] = 1;
    while (Q.size()) {
        int h = Q.front();
        Q.pop();
        if (h == to) {
            return dp[h];
        }
        for (int i = 1; i <= n; i++) {
            if (book[i] == 0 && dis[h][i] == 1) {
                Q.push(i);
                book[i] = 1;
                dp[i] = dp[h] + 1;
            }
        }
    }
    return -1;

}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    ifstream fin("G.in");
    if (fin.good()) cin.rdbuf(fin.rdbuf());

    while (cin >> n >> m >> from >> to) {
        fill(dis[0], dis[0] + maxn * maxn, 0);
        while (m--) {
            int x, y;
            cin >> x >> y;
            dis[x][y] = 1;
            dis[y][x] = 1;
        }
        cout << bfs(from, to) << endl;

    }

    return 0;
}